Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
how can I upload a file using "react-query" and "type-script"?

It's my API:

type UploadVideoParams = {
    videofile: File   
    channelId: string | number
    name: string
}
    
const uploadVideo = (
    { videofile, channelId, name }: UploadVideoParams,
    onUploadProgress: (...args: any) => void
) => {  
    const formData = new FormData()   

    appendFormDataIfTruthy(formData, 'videofile', videofile)   
    appendFormDataIfTruthy(formData, 'channelId', channelId)   
    appendFormDataIfTruthy(formData, 'name', name)
    
    const source = CancelToken.source()
    
    return [
        axiosInstance({
            url: '/videos/upload',
            method: 'POST',
            headers: { 'Content-Type': 'multipart/form-data' },
            data: formData,
            onUploadProgress,
            cancelToken: source.token,
        }).then(res => res.data),
        (msg: string) => {
            source.cancel(msg) 
        },
    ] 
}

How can I implement a react query hook for this API? We use typescript, react v17 and react-query v3.18.1.

I add this mutation but get this error in API:

export const useUploadMutation = () =>   
    useMutation(
        VideosService.uploadVideo.name,
        VideosService.uploadVideo as unknown as MutationFunction<unknown, UploadVideoParams>,
        {
            onSuccess: () => {   
                queryClient.invalidateQueries([VideosService.getVideos.name])  
                queryClient.invalidateQueries([VideosService.getChannelVideos.name])
            },
        }
    )

but my API has this Error:

const cancelUpload: any Type 'void | [Promise, (msg: string) => void]' must have a 'Symbol.iterator' method that returns an iterator.ts(2488)

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!